from django.db import models

# Create your models here.


class GoodsType(models.Model):
    """商品类型"""
    class Meta:
        db_table = 'goodstype'

    name = models.CharField(verbose_name="名字", max_length=50)
    sort = models.IntegerField(verbose_name='排序', default=0, blank=True)
    describe = models.CharField(verbose_name="描述", max_length=128, null=True, blank=True)


class Goods(models.Model):
    """
    商品表
    """
    class Meta:
        db_table = 'goods'

    ISSHELF = ((0, '不允许'), (1, '允许'))

    name = models.CharField(verbose_name="名字", max_length=512)
    sort = models.IntegerField(verbose_name='排序', default=0, blank=True)
    describe = models.CharField(verbose_name="描述", max_length=2048, null=True, blank=True)
    master = models.ForeignKey('merchant.MerchantInfo', verbose_name='商家', on_delete=models.CASCADE, null=True,
                               blank=True)
    type = models.ForeignKey('GoodsType', verbose_name='类型', on_delete=models.SET_NULL, null=True, blank=True)
    price = models.FloatField(verbose_name='价格', default=0.00, blank=True)
    shelf = models.IntegerField(verbose_name='是否上架', default=0, choices=ISSHELF, blank=True)
    createtime = models.DateTimeField(verbose_name="创建时间", auto_now_add=True, blank=True)
    updatetime = models.DateTimeField(verbose_name="更新时间", auto_now=True, blank=True)
    img = models.CharField(verbose_name="图片路径", max_length=1024, null=True, blank=True)


class RushGoods(models.Model):
    """
    抢购商品表
    """
    class Meta:
        db_table = 'rushgoods'

    goods = models.ForeignKey('Goods', verbose_name='商品', on_delete=models.SET_NULL, null=True, blank=True)
    rushprice = models.FloatField(verbose_name='抢购价格', default=0.00, blank=True)
    createtime = models.DateTimeField(verbose_name="创建时间", auto_now_add=True, blank=True)
    number = models.IntegerField(verbose_name='剩余数量', default=0, blank=True)
    total = models.IntegerField(verbose_name='抢购数量', default=0, blank=True)


class Order(models.Model):
    """
    订单
    """
    class Meta:
        db_table = 'order'
    ISRUSH = ((0, '否'), (1, '是'))
    uid = models.CharField(verbose_name="编号", max_length=128)
    goods = models.ForeignKey('Goods', verbose_name='商品', on_delete=models.SET_NULL, null=True, blank=True)
    price = models.FloatField(verbose_name='价格', default=0.00, blank=True)
    number = models.IntegerField(verbose_name='购买数量', default=0, blank=True)
    total = models.FloatField(verbose_name='总价格', default=0.00, blank=True)
    createtime = models.DateTimeField(verbose_name="创建时间", auto_now_add=True, blank=True)
    isrush = models.IntegerField(verbose_name='是否抢购', default=0, choices=ISRUSH, blank=True)
    user = models.ForeignKey('userManage.Loginuser', verbose_name='用户', on_delete=models.CASCADE, null=True, blank=True)
